const {ipcRenderer} = require('electron')
const time_h_down = document.getElementById("time_h_down");
const time_m_down = document.getElementById("time_m_down");

const date = new Date()

const year = date.getFullYear()
const month = date.getMonth() + 1; //获取的是0-11所以+1
const nowDate = date.getDate()

//时间缓冲
let time_h_buffer;
let time_m_buffer;



/*导航栏js */
let i = 0;
const change = () => {
    const pinnedImage = document.getElementById("pinnedImage");
    console.log(pinnedImage.src,i)
    if(i == 0){
        pinnedImage.style.transform = 'rotate3d(0,0,1,-45deg)';
        ipcRenderer.send('main-top')
        i = 1;
    }else{
        // pinnedImage.src = "images/Pinned_xie.svg"
        pinnedImage.style.transform = 'rotate3d(0,0,1,0deg)';
        ipcRenderer.send('main-no-top')
        i = 0;
    }
}

const clickClose = () => {
    ipcRenderer.send('main-close');
}

const h_switch_0 = document.getElementById("h_switch_0")
const h_switch_master = document.getElementById("h_switch_master")
const h_switch_2 = document.getElementById("h_switch_2")
const h_switch_3 = document.getElementById("h_switch_3")
const h_switch_4 = document.getElementById("h_switch_4")
const h_switch_5 = document.getElementById("h_switch_5")
const h_switch_6 = document.getElementById("h_switch_6")
const h_switch_7 = document.getElementById("h_switch_7")
const h_switch_8 = document.getElementById("h_switch_8")
const mouseUpClick = async(num) => {
    switch(num){
        case 0:
            h_switch_0.style.
            break;
        case 1:
            break;
        case 2:
            break;
        case 3:
            break;
        case 4:
            break;
        case 5:
            break;

    }
}

/**
 * 设置休息时间
 */
const sleep_h_time = document.getElementById("sleep_h_time");
const sleep_m_time = document.getElementById("sleep_m_time");


/**
 * 完成时按键
 *  */
const completeFunc = async() => {
    /*测试用 begin*/
/*     time_h_down.value = 18;
    time_m_down.value = 0; */
    /*测试用 end*/

    const time_now = await new Date()

    const downTime = await new Date(`${year}-${month}-${nowDate} ${time_h_down.value}:${time_m_down.value}:${00}`)
    console.log(date)
    console.log(time_h_down.value - time_now.getHours())

    if(time_m_down.value == 0){
        time_m_buffer =await 60;
        time_h_buffer =await time_h_down.value - 1;
    }else{
        time_m_buffer =await time_m_down.value;
        time_h_buffer = await time_h_down.value;
    }
    if(time_m_buffer == 60){
        time_h_buffer = await time_h_down.value - 1;
    }
    
    if(time_h_down.value >= 24){
        time_h_down.value = 0;
    }
    if(time_m_down.value >= 60){
        time_m_down.value = 0;
    }
    if(time_h_down.value < 24 || time_m_down.value < 60){
        //发生数据给electron主线程
        ipcRenderer.send('mainwin-new-win');//创建窗口
        ipcRenderer.send('getHour',time_h_buffer);
        ipcRenderer.send('getMinute',time_m_buffer);
    }
    //只是传入数据
    ipcRenderer.send('sleepTime_H',sleep_h_time.value);
    ipcRenderer.send('sleepTime_M',sleep_m_time.value);
    ipcRenderer.send('getTianQi')
    ipcRenderer.send('getLearnWin')
    
}

